package org.breathe.dynamic.thread.pool.starter.mysql.autoconfiguration;

/**
 * @author: breathe
 * @createTime: 2025-05-19
 */

import lombok.RequiredArgsConstructor;
import org.breathe.dynamic.thread.pool.starter.common.autoconfigure.BaseBeanAutoConfiguration;
import org.breathe.dynamic.thread.pool.starter.mysql.config.MysqlConfigProvider;
import org.breathe.dynamic.thread.pool.starter.mysql.refresh.MysqlRefresher;
import org.breathe.thread.pool.common.constant.BreatheDtpConstant;
import org.breathe.thread.pool.common.entity.BreatheDtpProperties;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 配置的自动注入
 * @author: breathe
 * @createTime: 2025-04-13
 */
@Configuration
@EnableConfigurationProperties(BreatheDtpProperties.class)
@ConditionalOnClass(MysqlConfigProvider.class)
@ConditionalOnProperty(value = BreatheDtpConstant.DTP_ENABLED_PROP, matchIfMissing = true, havingValue = "true")
@RequiredArgsConstructor
@ImportAutoConfiguration({BaseBeanAutoConfiguration.class})
public class BreatheDtpAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public MysqlConfigProvider mysqlConfigProvider() {
        return new MysqlConfigProvider();
    }
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass({BreatheDtpProperties.class, MysqlConfigProvider.class, JdbcTemplate.class})
    public MysqlRefresher mysqlRefresher() {
        return new MysqlRefresher();
    }
}

